package com.example.mysaat.service_menu_manual_test.allActivities;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import com.example.mysaat.R;
import com.example.mysaat.service_menu_manual_test.Listeners.MyFailOnclickListener;
import com.example.mysaat.service_menu_manual_test.Listeners.MyPassOnclickListener;

public class DisplayCheckActivity extends AppCompatActivity {

    private Button btn_pass = null;
    private Button btn_fail = null;
    private RelativeLayout layout = null;
    private static final String TAG = "DisplayCheckActivity";
    private boolean isBright = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_check);
        init();
        initContent();
        Message message = new Message();
        message.what = 1;
        handler.sendMessageDelayed(message,2000);
    }

    private void init(){
        btn_pass = findViewById(R.id.brightness_pass_btn);
        btn_fail = findViewById(R.id.brightness_fail_btn);
        layout = findViewById(R.id.relative_layout);
    }

    private void initContent(){
        btn_fail.setOnClickListener(new MyFailOnclickListener(DisplayCheckActivity.this,null));
        btn_pass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(isBright) {
                    layout.setBackgroundColor(Color.BLACK);
                    btn_fail.setBackground(getResources().getDrawable(R.drawable.shape_button_bg));
                    btn_pass.setBackground(getResources().getDrawable(R.drawable.shape_button_bg));
                    btn_pass.setTextColor(Color.WHITE);
                    btn_fail.setTextColor(Color.WHITE);
                    btn_pass.setVisibility(View.INVISIBLE);
                    btn_fail.setVisibility(View.INVISIBLE);
                    Message message = new Message();
                    message.what = 1;
                    handler.sendMessageDelayed(message,2000);
                }else{
                    //将结果统计到list列表之中
                    finish();
                }
                isBright = !isBright;
            }
        });
    }

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what==1){
                    btn_pass.setVisibility(View.VISIBLE);
                    btn_fail.setVisibility(View.VISIBLE);
            }
        }
    };

}
